package yuan.deng.jdbc;

import java.sql.*;

//快速入门
public class Demo1 {
    public static void main(String[] args) throws Exception{
        //导入jar包
        //注册驱动,全限定类名反射获取注册驱动对象  5版本后可以省略不做
        Class.forName("com.mysql.jdbc.Driver");
        //获取连接  1获取执行者对象，2管理事务,3释放资源
        Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.96.129:3306/db8", "root", "root");
        //获取执行者对象,执行sql语句
        Statement statement = connection.createStatement();
        //执行sql语句接受结果
        String sql="select * from student";
        ResultSet resultSet = statement.executeQuery(sql);
        //处理结果
        while (resultSet.next()){
            System.out.println(resultSet.getInt("id")+resultSet.getString("name")+resultSet.getInt("age"));
        }
        System.out.println(resultSet.toString());
        //释放资源
        statement.close();
        connection.close();
        }
}